package com.imy.luascript.utils;

import android.view.View;

import com.jakewharton.rxbinding.view.RxView;

import java.util.concurrent.TimeUnit;

import rx.functions.Action1;
import rx.subscriptions.CompositeSubscription;

/**
 * @ProjectName: frame
 * @Package: com.imy.base.utils
 * @ClassName: RxUtils
 * @Description: 描述
 * @Author: 蒋明伟
 * @CreateDate: 2020/10/26 16:29
 */
public class RxUtils {

    public static CompositeSubscription getNewCompositeSubIfUnsubscribed(
            CompositeSubscription subscription) {
        if (subscription == null || subscription.isUnsubscribed()) {
            return new CompositeSubscription();
        }
        return subscription;
    }

    //防重复点击
    public static void clicks(final View view, Action1 action1) {
        clicks(view, 1000, action1);
    }

    //防重复点击
    public static void clicks(final View view, long windowDuration, Action1 action1) {
        RxView.clicks(view)
                .throttleFirst(windowDuration, TimeUnit.MILLISECONDS)
                .subscribe(action1);
    }

}